package cn.wolfcode.luowowo.ticket.service.impl;

import cn.wolfcode.luowowo.ticket.domain.Ticket;
import cn.wolfcode.luowowo.ticket.domain.TicketOrder;
import cn.wolfcode.luowowo.ticket.mapper.TicketOrderMapper;
import cn.wolfcode.luowowo.ticket.service.ITicketOrderService;
import com.alibaba.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Date;
import java.util.List;

@Service
public class TicketOrderServiceImpl implements ITicketOrderService{

    @Autowired
    private TicketOrderMapper ticketOrderMapper;

    @Override
    public void saveOrUpdate(TicketOrder ticketOrder, Long ticketId) {
        if(ticketOrder.getId() != null){
            ticketOrderMapper.updateByPrimaryKey(ticketOrder);
        }else{
            ticketOrder.setCreateTime(new Date());
            Ticket ticket = new Ticket();
            ticket.setId(ticketId);
            ticketOrder.setTicket(ticket);
            ticketOrderMapper.insert(ticketOrder);
        }
    }

    @Override
    public TicketOrder get(Long id) {
        return ticketOrderMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<TicketOrder> list() {
        return ticketOrderMapper.selectAll();
    }

    @Override
    public List<TicketOrder> listAll() {
        return ticketOrderMapper.listAll();
    }
}
